import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';

import {Observable} from "rxjs/Observable";
import 'rxjs/add/operator/map';

@Injectable()
export class TeamOverviewProvider {
    constructor(private http:HttpClient){}

    /**
     * 获取团队业绩总揽
     * @returns {Observable<any>}
     */
    getTeamOverViewData():Observable<any>{
        const url = `/achieve/v1/tm_overview`;

        let mockData = {
            time:'2018-11',
            rank:32,
            nearBys:[
                {rank:29,agentCode:'SH30581',level:'DM',pc:'2988'},
                {rank:30,agentCode:'SH30582',level:'SDM',pc:'5877'},
                {rank:31,agentCode:'SH30583',level:'DD',pc:'6977'},
                {rank:32,agentCode:'SH30580',level:'SUM',pc:'2245'},
                {rank:33,agentCode:'SH30586',level:'SUM',pc:'2456'}
            ],
            directMonthPC:'8000',
            directYearPC:'10000',
            directHighestPC:'20000',
            underMonthPC:'80000',
            underYearPC:'160000',
            underHighestPC:'12000000'
        };

        return this.http.get(url).map((item) => {
            return item;
        })
    }

    /**
     * 获取列表
     * @param {string} start
     * @param {string} end
     * @returns {Observable<any>}
     */
    getGroupList(start:string,end:string):Observable<any>{
        const url = `/achieve/v1/groups?startTime=${start}&endTime=${end}`;
        let mockData = [
            {groupID:1,groupName:'艾中宏组1',isDirect:1,totalPC:2423,totalAPE:8998},
            {groupID:2,groupName:'艾中宏组2',isDirect:0,totalPC:1233,totalAPE:2344},
            {groupID:3,groupName:'艾中宏组3',isDirect:0,totalPC:345345,totalAPE:234234},
            {groupID:4,groupName:'艾中宏组4',isDirect:1,totalPC:1234,totalAPE:23451},
            {groupID:5,groupName:'艾中宏组5',isDirect:1,totalPC:32424,totalAPE:34656},
            {groupID:6,groupName:'艾中宏组6',isDirect:0,totalPC:4333,totalAPE:5656645},
            {groupID:7,groupName:'艾中宏组7',isDirect:0,totalPC:456,totalAPE:86998},
            {groupID:8,groupName:'艾中宏组8',isDirect:0,totalPC:45,totalAPE:869968},
            {groupID:9,groupName:'艾中宏组9',isDirect:1,totalPC:456,totalAPE:86998},
            {groupID:10,groupName:'艾中宏组11',isDirect:0,totalPC:4345633,totalAPE:89968},
            {groupID:11,groupName:'艾中宏组12',isDirect:0,totalPC:435633,totalAPE:86998},
        ];
        return this.http.get(url).map(item=>{
            return item;
        });
    }

    /**
     * 获取分组列表
     * @param {string} groupId
     * @param {string} start
     * @param {string} end
     * @returns {Observable<any>}
     */
    getMemberGroupList(groupId:string,start:string,end:string):Observable<any>{
        const url = `/achieve/v1/tm_members?groupId=${groupId}&startTime=${start}&endTime=${end}`;

        let mockData = [
            {agentCode:'SH30580',agentName:'FA',agentLevel:'Y',isEffective:0,totalPC:1000,totalAPE:50},
            {agentCode:'SH30581',agentName:'FA',agentLevel:'Y',isEffective:1,totalPC:2000,totalAPE:50},
            {agentCode:'SH30582',agentName:'FA',agentLevel:'N',isEffective:0,totalPC:3000,totalAPE:50},
            {agentCode:'SH30583',agentName:'FA',agentLevel:'Y',isEffective:1,totalPC:3300,totalAPE:50},
            {agentCode:'SH30584',agentName:'FA',agentLevel:'Y',isEffective:0,totalPC:3200,totalAPE:50},
            {agentCode:'SH30585',agentName:'FA',agentLevel:'Y',isEffective:1,totalPC:3100,totalAPE:50},
            {agentCode:'SH30586',agentName:'FA',agentLevel:'N',isEffective:0,totalPC:3900,totalAPE:50},
            {agentCode:'SH30587',agentName:'FA',agentLevel:'Y',isEffective:1,totalPC:3700,totalAPE:50},
            {agentCode:'SH30588',agentName:'FA',agentLevel:'N',isEffective:0,totalPC:3600,totalAPE:50},
            {agentCode:'SH30589',agentName:'FA',agentLevel:'Y',isEffective:0,totalPC:3500,totalAPE:50}
        ];

        return this.http.get(url).map(item=>{
            return item;
        });
    }

    /**
     * 获取详情
     * @param {number} type 1-个人业绩详情，2-团队业绩详情
     * @param {string} id
     * @param {string} start
     * @param {string} end
     * @returns {Observable<any>}
     */
    getPerformanceDetail(type:number,id:string,start:string,end:string):Observable<any>{
        let url = '';
        if(type === 1){
            url = `/achieve/v1/personal_achieve?id=${id}&startTime=${start}&endTime=${end}`;
        }else {
            url = `/achieve/v1/tm_detail?groupId=${id}&startTime=${start}&endTime=${end}`;
        }
        let mockData = {
            totalPolicy:2000,
            totalPC:1231,
            totalAPE:4588,
            totalCommission:65443,
            lfNetCaseCount:3332,
            paNetCaseCount:3123,
            indNetPc:423,
            indNetApe:34345,
            indNetFyc:8765,
            glhNetCaseCount:67675,
            glhNetPc:66456,
            glhNetApe:98977,
            glhNetFyc:234,
            gpNetCaseCount:9988,
            gpNetPc:78676,
            gpNetApe:5433,
            gpNetFyc:655454,
            mfNetPc:9876,
            mfNetFyc:8754,
            lf13MonthConsrvRate:9875,
            lf19MonthConsrvRate:51432,
            threeMoIndex:876,
            indexActive:985,
            cmpPrintNum:4358
        };
        return this.http.get(url).map(item=>{
            return item;
        });
    }
}
